<template>
    <div class="region">
        <div class="content">
            <div class="left">地区:</div>
            <ul>
                <li :class="{active:activeFlag==''}" @click="changeRegion('')">全部</li>
                <li :class="{active:activeFlag==region.value}" @click="changeRegion(region.value)"
                    v-for="region in regionArr" :key="region.value">{{ region.name }}
                </li>
            </ul>
        </div>
    </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from "vue";
import {HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData} from "@/api/home/type.ts";
import {reqHospitalLevelAndRegion} from "@/api/home/index.ts";

let regionArr = ref<HospitalLevelAndRegionArr>([])
let activeFlag = ref("")
onMounted(() => {
    getRegion()
})

const getRegion = async () => {
    let result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("Beijin")
    if (result.code == 200) {
        regionArr.value = result.data
    }
}
const changeRegion = (region: string) => {
    activeFlag.value = region
    $emit('getRegion',region)
}


let $emit = defineEmits(['getRegion']);





</script>
<script lang="ts">
export default {
name: 'Region'
}

</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;

  .content {
    display: flex;

    .left {
      margin-right: -8px;
      width: 45px;
    }

    ul {
      margin-top: 0;
      display: flex;
      flex-wrap: wrap;

      li {
        align-items: center;
        display: flex;
        margin-right: 15px;
        margin-bottom: 10px;

        &.active {
          color: #55a6fe;
        }
      }

      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}


</style>